<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="../js/vue.js"></script>
</head>
<script>
        // for(let i= 0; i < arr.length; i++){

        // }
        // for(let attr in obj){
        //     obj[attr]
        // }
</script>

<body>
    <div id="demo">
        <ul>
            <li v-for="(todo, index) in todos" :key="todo.id">
                {{index}} - {{todo.title}} <input type="text" name="" id="">
            </li>
        </ul>
        <p><button @click="addHead">从头添加</button></p>
        <p><button @click="addBack">从尾添加</button></p>
    </div>
    <script>
        Vue.config.productionTip = false
        new Vue({
            el: '#demo',
            data: {
                todos: [
                    {
                        id: 1,
                        title: '吃饭',
                        isDone: false
                    },
                    {
                        id: 2,
                        title: '睡觉',
                        isDone: false
                    },
                    {
                        id: 3,
                        title: '敲代码',
                        isDone: true
                    }
                ]
            },
            methods:{
                addHead(){
                    let todo = {
                        id:100,
                        title:'我是头部信息',
                        isDone:false
                    }
                    this.todos.unshift(todo)
                },
                addBack(){
                    let todo = {
                        id:200,
                        title:'我是尾部信息',
                        isDone:false
                    }
                    this.todos.push(todo)
                }
            }
        })
    </script>
</body>

</html>